home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / misc / TownMaze.lha / TownMaze / src.lzh / movefromto.c < prev    next >
C/C++ Source or Header  |  1991-08-04  |  1KB  |  77 lines

  1. /*
  2. ** movefromto.c  Copyright 1991 Kent Paul Dolan,
  3. **               Mountain View, CA, USA 94039-0755
  4. **
  5. ** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  6. ** May be freely used or modified in any non-commercial work.  Copyrighted
  7. ** only to prevent patenting by someone else.
  8. */
  9.  
  10. #include <stdio.h>
  11. #include "townmaze.h"
  12. #include "townproto.h"
  13.  
  14. #ifdef __STDC__
  15. void movefromto(int *fromlist,int *fromcount,int *tolist,int *tocount,
  16.                 int newstat,int cellnum)
  17. #else
  18. int movefromto(fromlist,fromcount,tolist,tocount,newstat,cellnum)
  19.   int *fromlist;
  20.   int *fromcount;
  21.   int *tolist;
  22.   int *tocount;
  23.   int newstat;
  24.   int cellnum;
  25. #endif
  26. {
  27.  
  28.   int oldnext;
  29.   int oldprev;
  30.  
  31. /*
  32. ** Save vital existing links.
  33. */
  34.  
  35.   oldnext = statlist[cellnum].next;
  36.   oldprev = statlist[cellnum].prev;
  37.  
  38. /*
  39. ** Unlink cell from old position somewhere in fromlist.
  40. */
  41.  
  42.   if (statlist[cellnum].next != NOPOINTER)
  43.     statlist[oldnext].prev = statlist[cellnum].prev;
  44.  
  45.   if (statlist[cellnum].prev != NOPOINTER)
  46.     statlist[oldprev].next = statlist[cellnum].next;
  47.   else *fromlist = statlist[cellnum].next;
  48.  
  49. /*
  50. ** Link cell into new position at head of tolist.
  51. */
  52.  
  53.   statlist[cellnum].next = *tolist;
  54.  
  55.   statlist[cellnum].prev = NOPOINTER;
  56.  
  57.   if (*tolist != NOPOINTER)
  58.     statlist[*tolist].prev = cellnum;
  59.  
  60.   *tolist = cellnum;
  61.  
  62. /*
  63. ** Update list length counts.
  64. */
  65.  
  66.   (*fromcount)--;
  67.   (*tocount)++;
  68.  
  69. /*
  70. ** update cell status
  71. */
  72.  
  73.       statlist[cellnum].status = newstat;
  74.  
  75.   return;
  76. }
  77.